package com.situ.crm2026.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.situ.crm2026.dao.MemberMapper;
import com.situ.crm2026.model.Member;
import com.situ.crm2026.model.search.MemberSearchBean;

import com.situ.crm2026.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@CacheConfig(cacheNames = "com.situ.crm2026.impl.memberServiceImpl")
public class MemberServiceImpl implements MemberService {
    private MemberMapper memberMapper;

    @Autowired
    public MemberServiceImpl(MemberMapper memberMapper) {
        this.memberMapper = memberMapper;
    }
  //  @Cacheable(key = "'member-page-' + #page.current + '-' + #page.size + '-' + (#msb?.name ?: 'all') + '-' + (#msb?.phone ?: 'all')")
    @Override
    public Page<Member> findAll(Page<Member> page, MemberSearchBean member) {
        return memberMapper.findAll(page, member);
    }
    @CacheEvict(allEntries=true)
    @Override
    @Transactional
    public int deleteByIds(List<Integer> ids) {
        return memberMapper.deleteByIds(ids);
    }
    @CacheEvict(allEntries=true)
    @Override
    public boolean save(Member member) {
        return memberMapper.insert(member) == 1;
    }
    @CacheEvict(allEntries=true)
    @Override
    public boolean update(Member member) {
        return memberMapper.updateById(member) == 1;
    }
}
